<template>
  <div class="app-container">
    <!-- 顶部搜索 -->
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="100px">
      <el-form-item label="专利名称" prop="zlName">
        <el-input size="mini"
                  v-model="queryParams.zlName"
                  placeholder="请输入专利名称"
                  clearable
                  @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="申请年度" prop="sqNd">
        <el-select size="mini" v-model="queryParams.sqNd" placeholder="请选择申请年度" clearable>
          <el-option
            v-for="dict in dict.type.year"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="流程状态:" prop="processStatus">
        <el-select v-model="queryParams.processStatus" placeholder="请选择流程状态" clearable size="mini">
          <el-option
            v-for="dict in dict.type.zl_lczt"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="专利类型" prop="zlLx">
        <el-select size="mini" v-model="queryParams.zlLx" placeholder="请选择专利类型" clearable>
          <el-option
            v-for="dict in dict.type.zlsbnn_zllx"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="所属领域" prop="ssLy">
        <el-select size="mini" v-model="queryParams.ssLy" placeholder="请选择所属领域" clearable>
          <el-option
            v-for="dict in dict.type.kylx_ssly"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="依托工程" prop="ytGc">
        <el-input size="mini"
                  v-model="queryParams.ytGc"
                  placeholder="请输入依托工程"
                  clearable
                  @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="专利发明人" prop="zlFmr">
        <el-input size="mini"
                  v-model="queryParams.zlFmr"
                  placeholder="请输入专利发明人"
                  clearable
                  @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="申报单位" prop="sbDw">
        <el-input size="mini"
                  v-model="queryParams.sbDw"
                  placeholder="请输入申报单位"
                  clearable
                  @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <!-- 顶部按钮 -->
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-edit"
          size="mini"
          :disabled="!selectedRow || (selectedRow.processStatus != 3 && selectedRow.processStatus != 6)"
          @click="zlSqUpdate"
        >专利申请信息填写
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-edit"
          size="mini"
          :disabled="!selectedRow || (selectedRow.processStatus != 5)"
          @click="zlSqcgUpdate"
        >专利授权信息填写
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['zlsb:zlsb:export']"
        >导出
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <!-- 表格 -->
    <el-table @row-click="clickRow" ref="table" highlight-current-row
              :header-cell-style="{background:'#d0cece',color:'#000000',fontWeight:'bold'}"
              v-loading="loading" :data="zlsbList" @selection-change="handleSelectionChange">
      <!--      <el-table-column type="selection" width="55" align="center"/>-->
      <el-table-column label="序号" align="center" type="index" width="50"/>
      <el-table-column label="申请年度" align="center" prop="sqNd" show-overflow-tooltip>
        <template slot-scope="scope">
          <dict-tag :options="dict.type.year" :value="scope.row.sqNd"/>
        </template>
      </el-table-column>
      <el-table-column label="专利名称" align="center" prop="zlName" show-overflow-tooltip>
        <template slot-scope="scope">
          <el-button
            type="text"
            @click="handleButtonClick(scope.row)"
          >
            <el-link type="primary">{{ scope.row.zlName }}</el-link>
          </el-button>
        </template>
      </el-table-column>
      <el-table-column label="依托工程" align="center" prop="ytGc" show-overflow-tooltip/>
      <el-table-column label="实施日期" align="center" prop="ssRq" width="180" show-overflow-tooltip>
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.ssRq, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="专利类型" align="center" prop="zlLx" show-overflow-tooltip>
        <template slot-scope="scope">
          <dict-tag :options="dict.type.zlsbnn_zllx" :value="scope.row.zlLx"/>
        </template>
      </el-table-column>
      <el-table-column label="所属领域" align="center" prop="ssLy" show-overflow-tooltip>
        <template slot-scope="scope">
          <dict-tag :options="dict.type.kylx_ssly" :value="scope.row.ssLy"/>
        </template>
      </el-table-column>
      <el-table-column label="申报单位" align="center" prop="sbDw" show-overflow-tooltip>
        <template slot-scope="scope">
          <dict-tag :options="dict.type.xmgl_lxwj_pzdw" :value="scope.row.sbDw"/>
        </template>
      </el-table-column>
      <el-table-column label="第一发明人" align="center" prop="dyFmr" show-overflow-tooltip/>
      <el-table-column label="其他发明人" align="center" prop="qtFmr" show-overflow-tooltip/>
      <el-table-column label="申报日期" align="center" prop="sbTime" width="180" show-overflow-tooltip>
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.sbTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="服务机构" align="center" prop="qqFwJg" show-overflow-tooltip>
        <template slot-scope="scope">
          <dict-tag :options="dict.type.zlsb_qqfwjg" :value="scope.row.qqFwJg"/>
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" prop="processStatus" width="120">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.zl_lczt" :value="scope.row.processStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleJinDu(scope.row)"
            v-if="scope.row.processStatus !== 1"
          >查询进度
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <!-- 分页组件 -->
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 专利申请信息填写对话框 -->
    <vxe-modal :title="title" v-model="open" width="65%" showFooter show-zoom resize>
      <el-form ref="formDialog" :model="form" :rules="rules" label-width="110px">
        <el-tabs type="border-card" v-model="activeName">
          <!-- 专利知产申请信息 -->
          <el-tab-pane name="zlzcsqxx" :lazy=true>
            <span slot="label"><i class="el-icon-date"></i> 专利知产申请信息</span>
            <div v-if="activeName === 'zlzcsqxx'" style="height: 65vh; overflow-y: auto;">
              <el-card class="box-card" shadow="never">
                <div slot="header" class="clearfix" style="text-align: center;">
                  <span style="font-size: 20px; color: #1890ff">专利知产申请信息</span>
                </div>
                <el-row :gutter="24">
                  <el-col :span="12">
                    <el-form-item label="申请日期" prop="sqSqTime">
                      <el-date-picker clearable style="width: 100%"
                                      v-model="form.sqSqTime"
                                      type="date"
                                      value-format="yyyy-MM-dd"
                                      placeholder="请选择申请日期">
                      </el-date-picker>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="定稿名称" prop="sqDgName">
                      <el-input v-model="form.sqDgName" placeholder="请输入定稿名称"/>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row :gutter="24">
                  <el-col :span="12">
                    <el-form-item label="授权日期" prop="sqTime">
                      <el-date-picker clearable style="width: 100%" disabled
                                      v-model="form.sqTime"
                                      type="date"
                                      value-format="yyyy-MM-dd"
                                      placeholder="请选择授权日期">
                      </el-date-picker>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="专利号" prop="sqZlh">
                      <el-input v-model="form.sqZlh" placeholder="请输入专利号"/>
                    </el-form-item>
                  </el-col>
                </el-row>
              </el-card>
            </div>
          </el-tab-pane>

          <!-- 基本资料 -->
          <el-tab-pane name="jbzl" :lazy=true>
            <span slot="label"><i class="el-icon-date"></i> 基本资料</span>
            <div v-if="activeName === 'jbzl'" style="height: 65vh; overflow-y: auto;">
              <el-card class="box-card" shadow="never">
                <div slot="header" class="clearfix" style="text-align: center;">
                  <span style="font-size: 20px; color: #1890ff">专利基本资料</span>
                </div>
                <el-row :gutter="24">
                  <el-col :span="12">
                    <el-form-item label="专利名称" prop="zlName">
                      <el-input disabled v-model="form.zlName" placeholder="请输入专利名称"/>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="申请年度" prop="sqNd">
                      <el-select disabled v-model="form.sqNd" placeholder="请选择申请年度">
                        <el-option
                          v-for="dict in dict.type.year"
                          :key="dict.value"
                          :label="dict.label"
                          :value="dict.value"
                        ></el-option>
                      </el-select>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row :gutter="24">
                  <el-col :span="12">
                    <el-form-item label="专利类型" prop="zlLx">
                      <el-select disabled v-model="form.zlLx" placeholder="请选择专利类型">
                        <el-option
                          v-for="dict in dict.type.zlsbnn_zllx"
                          :key="dict.value"
                          :label="dict.label"
                          :value="dict.value"
                        ></el-option>
                      </el-select>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item si label="申报日期" prop="sbTime">
                      <el-date-picker disabled clearable style="width: 100%"
                                      v-model="form.sbTime"
                                      type="date"
                                      value-format="yyyy-MM-dd"
                                      placeholder="请选择申报日期">
                      </el-date-picker>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row :gutter="24">
                  <el-col :span="12">
                    <el-form-item label="所属领域" prop="ssLy">
                      <el-select disabled v-model="form.ssLy" placeholder="请选择所属领域">
                        <el-option
                          v-for="dict in dict.type.kylx_ssly"
                          :key="dict.value"
                          :label="dict.label"
                          :value="dict.value"
                        ></el-option>
                      </el-select>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="依托工程" prop="ytGc">
                      <el-input disabled v-model="form.ytGc" placeholder="请输入依托工程"/>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row :gutter="24">
                  <el-col :span="12">
                    <el-form-item label="实施日期" prop="ssRq">
                      <el-date-picker disabled clearable style="width: 100%"
                                      v-model="form.ssRq"
                                      type="date"
                                      value-format="yyyy-MM-dd"
                                      placeholder="请选择实施日期">
                      </el-date-picker>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="身份证号码" prop="sfzHm">
                      <el-input disabled v-model="form.sfzHm" placeholder="请输入身份证号码"/>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row :gutter="24">
                  <el-col :span="12">
                    <el-form-item label="第一发明人" prop="dyFmr">
                      <el-input disabled v-model="form.dyFmr" placeholder="请输入第一发明人" @focus="selectKjry"
                                :suffix-icon="'el-icon-search'"/>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="其他发明人" prop="qtFmr">
                      <el-input disabled v-model="form.qtFmr" placeholder="请输入其他发明人" @focus="selectUser(form.kjryId)"
                                :suffix-icon="'el-icon-search'"/>
                    </el-form-item>
                    <el-form-item v-if="1 === 2" label="科技人员ID" prop="qtFmr">
                      <el-input disabled v-model="form.kjryId" placeholder="请输入科技人员ID"/>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row :gutter="24">
                  <el-col :span="12">
                    <el-form-item label="申报单位" prop="sbDw">
                      <el-select disabled v-model="form.sbDw" placeholder="请选择申报单位">
                        <el-option
                          v-for="dict in dict.type.xmgl_lxwj_pzdw"
                          :key="dict.value"
                          :label="dict.label"
                          :value="dict.value"
                        ></el-option>
                      </el-select>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="专利权人" prop="zlqR">
                      <el-input disabled v-model="form.zlqR" placeholder="请输入专利权人"/>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row :gutter="24">
                  <el-col :span="12">
                    <el-form-item label="联系人" prop="lxr">
                      <el-input disabled v-model="form.lxr" placeholder="请输入联系人"/>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="联系电话" prop="lxPhone">
                      <el-input disabled v-model="form.lxPhone" placeholder="请输入联系电话"/>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row :gutter="24">
                  <el-col :span="12">
                    <el-form-item label="前期服务机构" prop="qqFwJg">
                      <el-select disabled v-model="form.qqFwJg" placeholder="请选择前期服务机构">
                        <el-option
                          v-for="dict in dict.type.zlsb_qqfwjg"
                          :key="dict.value"
                          :label="dict.label"
                          :value="dict.value"
                        ></el-option>
                      </el-select>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="备注" prop="bz">
                      <el-input disabled v-model="form.bz" type="textarea" placeholder="请输入内容"/>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-form-item label="科研项目" prop="kyXm" @focus="selectKt">
                  <el-input disabled v-model="form.kyXm" placeholder="请关联科研项目">
<!--                    <el-button slot="append" icon="el-icon-search" @click="selectKt" style="color: #1890ff">查询项目列表-->
<!--                    </el-button>-->
                  </el-input>
                </el-form-item>
                <el-form-item v-if="1 === 2" label="项目申报ID" prop="xmsbId">
                  <el-input v-model="form.xmsbId" placeholder="请输入项目申报ID"/>
                </el-form-item>
              </el-card>
            </div>
          </el-tab-pane>

          <!-- 专利资料 -->
          <el-tab-pane name="zlzl" :lazy=true>
            <span slot="label"><i class="el-icon-date"></i> 专利资料</span>
            <div v-if="activeName === 'zlzl'" style="height: 65vh; overflow-y: auto;">
              <el-card class="box-card" shadow="never">
                <div slot="header" class="clearfix" style="text-align: center;">
                  <span style="font-size: 20px; color: #1890ff">专利资料(专利技术交底书、说明书、说明书附图、cad图 、其他资料及图片)</span>
                </div>

                <el-row :gutter="20">
                  <el-col :span="4" :xs="24">
                    <div class="head-container">
                      <el-tree
                        :data="fileOptions"
                        :props="defaultProps"
                        :expand-on-click-node="false"
                        :filter-node-method="filterNode"
                        ref="tree"
                        node-key="id"
                        default-expand-all
                        highlight-current
                        @node-click="handleNodeClick"
                        :render-content="renderContent"
                      />
                    </div>
                  </el-col>
                  <el-col :span="20" :xs="24">
                    <el-row :gutter="10" class="mb8">
                      <el-col :span="1.5">
                        <!-- 上传按钮 -->
                        <el-button size="mini" icon="el-icon-upload" type="primary" @click="zlsbFileUpload">上传
                        </el-button>
                      </el-col>
                      <el-col :span="1.5">
                        <el-button type="danger" icon="el-icon-delete" size="mini" @click="handleDeleteZlglZlsbFj">删除
                        </el-button>
                      </el-col>
                    </el-row>
                    <el-table v-loading="loadingFj" height="50vh"
                              :header-cell-style="{background:'#d0cece',color:'#000000',fontWeight:'bold'}"
                              :data="zlglZlsbFjList" @selection-change="handleZlglZlsbFjSelectionChange"
                              ref="zlglZlsbFj">
                      <el-table-column type="selection" width="50" align="center"/>
                      <el-table-column label="序号" align="center" type="index" width="50"/>
                      <el-table-column label="文件类型" align="center" prop="fileType" width="150" show-overflow-tooltip/>
                      <el-table-column label="文件名称" align="center" prop="fileName" :formatter="getFileNames"
                                       show-overflow-tooltip/>
                      <el-table-column label="文件大小" align="center" prop="fileSize" width="150" show-overflow-tooltip/>
                      <el-table-column label="操作" align="center" width="150">
                        <template slot-scope="scope">
                          <el-button
                            size="mini"
                            type="text"
                            icon="el-icon-download"
                            @click="handleDownload(scope.row)"
                          >下载
                          </el-button>
                        </template>
                      </el-table-column>
                    </el-table>
                  </el-col>
                </el-row>
              </el-card>
            </div>
          </el-tab-pane>

        </el-tabs>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </vxe-modal>

    <!-- 专利授权信息填写对话框 -->
    <vxe-modal :title="title" v-model="zlSq" width="65%" showFooter show-zoom resize>
      <el-form ref="formDialog" :model="form" :rules="zlSqRules" label-width="110px">
        <el-tabs type="border-card" v-model="activeName">
          <!-- 专利知产申请信息 -->
          <el-tab-pane name="zlzcsqxx" :lazy=true>
            <span slot="label"><i class="el-icon-date"></i> 专利知产申请信息</span>
            <div v-if="activeName === 'zlzcsqxx'" style="height: 65vh; overflow-y: auto;">
              <el-card class="box-card" shadow="never">
                <div slot="header" class="clearfix" style="text-align: center;">
                  <span style="font-size: 20px; color: #1890ff">专利知产申请信息</span>
                </div>
                <el-row :gutter="24">
                  <el-col :span="12">
                    <el-form-item label="申请日期" prop="sqSqTime">
                      <el-date-picker clearable style="width: 100%"
                                      v-model="form.sqSqTime"
                                      type="date" disabled
                                      value-format="yyyy-MM-dd"
                                      placeholder="请选择申请日期">
                      </el-date-picker>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="定稿名称" prop="sqDgName">
                      <el-input disabled v-model="form.sqDgName" placeholder="请输入定稿名称"/>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row :gutter="24">
                  <el-col :span="12">
                    <el-form-item label="授权日期" prop="sqTime">
                      <el-date-picker clearable style="width: 100%"
                                      v-model="form.sqTime"
                                      type="date"
                                      value-format="yyyy-MM-dd"
                                      placeholder="请选择授权日期">
                      </el-date-picker>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="专利号" prop="sqZlh">
                      <el-input disabled v-model="form.sqZlh" placeholder="请输入专利号"/>
                    </el-form-item>
                  </el-col>
                </el-row>
              </el-card>
            </div>
          </el-tab-pane>

          <!-- 基本资料 -->
          <el-tab-pane name="jbzl" :lazy=true>
            <span slot="label"><i class="el-icon-date"></i> 基本资料</span>
            <div v-if="activeName === 'jbzl'" style="height: 65vh; overflow-y: auto;">
              <el-card class="box-card" shadow="never">
                <div slot="header" class="clearfix" style="text-align: center;">
                  <span style="font-size: 20px; color: #1890ff">专利基本资料</span>
                </div>
                <el-row :gutter="24">
                  <el-col :span="12">
                    <el-form-item label="专利名称" prop="zlName">
                      <el-input disabled v-model="form.zlName" placeholder="请输入专利名称"/>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="申请年度" prop="sqNd">
                      <el-select disabled v-model="form.sqNd" placeholder="请选择申请年度">
                        <el-option
                          v-for="dict in dict.type.year"
                          :key="dict.value"
                          :label="dict.label"
                          :value="dict.value"
                        ></el-option>
                      </el-select>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row :gutter="24">
                  <el-col :span="12">
                    <el-form-item label="专利类型" prop="zlLx">
                      <el-select disabled v-model="form.zlLx" placeholder="请选择专利类型">
                        <el-option
                          v-for="dict in dict.type.zlsbnn_zllx"
                          :key="dict.value"
                          :label="dict.label"
                          :value="dict.value"
                        ></el-option>
                      </el-select>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item si label="申报日期" prop="sbTime">
                      <el-date-picker disabled clearable style="width: 100%"
                                      v-model="form.sbTime"
                                      type="date"
                                      value-format="yyyy-MM-dd"
                                      placeholder="请选择申报日期">
                      </el-date-picker>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row :gutter="24">
                  <el-col :span="12">
                    <el-form-item label="所属领域" prop="ssLy">
                      <el-select disabled v-model="form.ssLy" placeholder="请选择所属领域">
                        <el-option
                          v-for="dict in dict.type.kylx_ssly"
                          :key="dict.value"
                          :label="dict.label"
                          :value="dict.value"
                        ></el-option>
                      </el-select>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="依托工程" prop="ytGc">
                      <el-input disabled v-model="form.ytGc" placeholder="请输入依托工程"/>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row :gutter="24">
                  <el-col :span="12">
                    <el-form-item label="实施日期" prop="ssRq">
                      <el-date-picker disabled clearable style="width: 100%"
                                      v-model="form.ssRq"
                                      type="date"
                                      value-format="yyyy-MM-dd"
                                      placeholder="请选择实施日期">
                      </el-date-picker>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="身份证号码" prop="sfzHm">
                      <el-input disabled v-model="form.sfzHm" placeholder="请输入身份证号码"/>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row :gutter="24">
                  <el-col :span="12">
                    <el-form-item label="第一发明人" prop="dyFmr">
                      <el-input disabled v-model="form.dyFmr" placeholder="请输入第一发明人" @focus="selectKjry"
                                :suffix-icon="'el-icon-search'"/>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="其他发明人" prop="qtFmr">
                      <el-input disabled v-model="form.qtFmr" placeholder="请输入其他发明人" @focus="selectUser(form.kjryId)"
                                :suffix-icon="'el-icon-search'"/>
                    </el-form-item>
                    <el-form-item v-if="1 === 2" label="科技人员ID" prop="qtFmr">
                      <el-input disabled v-model="form.kjryId" placeholder="请输入科技人员ID"/>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row :gutter="24">
                  <el-col :span="12">
                    <el-form-item label="申报单位" prop="sbDw">
                      <el-select disabled v-model="form.sbDw" placeholder="请选择申报单位">
                        <el-option
                          v-for="dict in dict.type.xmgl_lxwj_pzdw"
                          :key="dict.value"
                          :label="dict.label"
                          :value="dict.value"
                        ></el-option>
                      </el-select>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="专利权人" prop="zlqR">
                      <el-input disabled v-model="form.zlqR" placeholder="请输入专利权人"/>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row :gutter="24">
                  <el-col :span="12">
                    <el-form-item label="联系人" prop="lxr">
                      <el-input disabled v-model="form.lxr" placeholder="请输入联系人"/>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="联系电话" prop="lxPhone">
                      <el-input disabled v-model="form.lxPhone" placeholder="请输入联系电话"/>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row :gutter="24">
                  <el-col :span="12">
                    <el-form-item label="前期服务机构" prop="qqFwJg">
                      <el-select disabled v-model="form.qqFwJg" placeholder="请选择前期服务机构">
                        <el-option
                          v-for="dict in dict.type.zlsb_qqfwjg"
                          :key="dict.value"
                          :label="dict.label"
                          :value="dict.value"
                        ></el-option>
                      </el-select>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="备注" prop="bz">
                      <el-input disabled v-model="form.bz" type="textarea" placeholder="请输入内容"/>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-form-item label="科研项目" prop="kyXm" @focus="selectKt">
                  <el-input disabled v-model="form.kyXm" placeholder="请关联科研项目">
                    <!--                    <el-button slot="append" icon="el-icon-search" @click="selectKt" style="color: #1890ff">查询项目列表-->
                    <!--                    </el-button>-->
                  </el-input>
                </el-form-item>
                <el-form-item v-if="1 === 2" label="项目申报ID" prop="xmsbId">
                  <el-input v-model="form.xmsbId" placeholder="请输入项目申报ID"/>
                </el-form-item>
              </el-card>
            </div>
          </el-tab-pane>

          <!-- 专利资料 -->
          <el-tab-pane name="zlzl" :lazy=true>
            <span slot="label"><i class="el-icon-date"></i> 专利资料</span>
            <div v-if="activeName === 'zlzl'" style="height: 65vh; overflow-y: auto;">
              <el-card class="box-card" shadow="never">
                <div slot="header" class="clearfix" style="text-align: center;">
                  <span style="font-size: 20px; color: #1890ff">专利资料(专利技术交底书、说明书、说明书附图、cad图 、其他资料及图片)</span>
                </div>

                <el-row :gutter="20">
                  <el-col :span="4" :xs="24">
                    <div class="head-container">
                      <el-tree
                        :data="fileOptions"
                        :props="defaultProps"
                        :expand-on-click-node="false"
                        :filter-node-method="filterNode"
                        ref="tree"
                        node-key="id"
                        default-expand-all
                        highlight-current
                        @node-click="handleNodeClick"
                        :render-content="renderContent"
                      />
                    </div>
                  </el-col>
                  <el-col :span="20" :xs="24">
                    <el-row :gutter="10" class="mb8">
                      <el-col :span="1.5">
                        <!-- 上传按钮 -->
                        <el-button size="mini" icon="el-icon-upload" type="primary" @click="zlsbFileUpload">上传
                        </el-button>
                      </el-col>
                      <el-col :span="1.5">
                        <el-button type="danger" icon="el-icon-delete" size="mini" @click="handleDeleteZlglZlsbFj">删除
                        </el-button>
                      </el-col>
                    </el-row>
                    <el-table v-loading="loadingFj" height="50vh"
                              :header-cell-style="{background:'#d0cece',color:'#000000',fontWeight:'bold'}"
                              :data="zlglZlsbFjList" @selection-change="handleZlglZlsbFjSelectionChange"
                              ref="zlglZlsbFj">
                      <el-table-column type="selection" width="50" align="center"/>
                      <el-table-column label="序号" align="center" type="index" width="50"/>
                      <el-table-column label="文件类型" align="center" prop="fileType" width="150" show-overflow-tooltip/>
                      <el-table-column label="文件名称" align="center" prop="fileName" :formatter="getFileNames"
                                       show-overflow-tooltip/>
                      <el-table-column label="文件大小" align="center" prop="fileSize" width="150" show-overflow-tooltip/>
                      <el-table-column label="操作" align="center" width="150">
                        <template slot-scope="scope">
                          <el-button
                            size="mini"
                            type="text"
                            icon="el-icon-download"
                            @click="handleDownload(scope.row)"
                          >下载
                          </el-button>
                        </template>
                      </el-table-column>
                    </el-table>
                  </el-col>
                </el-row>
              </el-card>
            </div>
          </el-tab-pane>

        </el-tabs>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </vxe-modal>

    <!-- 附件上传弹窗 -->
    <vxe-modal title="附件上传" v-model="fjUpload" width="25%" showFooter show-zoom resize @close="fjClose">
      <el-upload
        align="center"
        class="upload-demo"
        multiple
        :action="uploadFileUrl"
        :before-upload="handleBeforeUpload"
        :file-list="fileList"
        :limit="20"
        :on-error="handleUploadError"
        :on-exceed="handleExceed"
        :on-success="handleUploadSuccess"
        :headers="headers"
        ref="fileUpload"
        drag
      >
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
        <div class="el-upload__tip" slot="tip">
          请上传
          <template> 大小不超过 <b style="color: #f56c6c">{{ 50 }}MB</b></template>
          <template v-if="fileType"> 格式为 <b style="color: #f56c6c">{{ fileType.join("/") }}</b></template>
          的文件
        </div>
      </el-upload>

      <div slot="footer" class="dialog-footer" style="display: flex; justify-content: center;">
        <el-button v-if="allFilesUploaded === false" size="mini" type="primary" @click="fjUpload = false">关 闭
        </el-button>
        <el-button v-if="allFilesUploaded === true" size="mini" type="primary" @click="fjClose">上传完成, 关闭
        </el-button>
      </div>

    </vxe-modal>

    <!-- 查询进度 -->
    <Jindu ref="picture"/>

    <!-- 专利申报详情 -->
    <ZlSbXq ref="zlSbXq"/>

  </div>
</template>

<script>
import {
  addZlsb,
  delZlFj,
  delZlsb,
  getZlsb,
  insertZlsbFjByZlsbId,
  selectZlBySqDj,
  selectZlsbFjList,
  updateZlsb, zlSqcgUpdate, zlSqUpdate
} from "@/api/zscq/zlsb/zlsb";
import {getToken} from "@/utils/auth";
import HtXzKt from "@/views/components/ktXz/HtXzKt.vue";
import ImagePreviewBase64 from "@/components/ImagePreviewBase64/index.vue";
import Jindu from "@/views/components/liuChengState/jindu.vue";
import ZlSbXq from "@/views/zscq/zlgl/zlsb/components/ZlSbXq.vue";

export default {
  name: "sqDj",
  components: {ZlSbXq, Jindu, ImagePreviewBase64, HtXzKt},
  dicts: ['xmgl_lxwj_pzdw', 'zlsb_qqfwjg', 'year', 'zlsbnn_zllx', 'kylx_ssly', 'zl_lczt'],
  watch: {
    activeName(newVal) {
      if (newVal === 'zlzl') {
        this.clickFirstNode();
      }
    },
  },
  mounted() {
    if (this.activeName === 'zlzl') {
      this.clickFirstNode();
    }
  },
  data() {
    return {
      zlSq: false, //专利授权信息填写对话框
      selectedRow: null, // 保存当前选中的行
      zlsbFileType: "专利资料", //默认的附件类型
      defaultProps: {children: "children", label: "label"}, // 表单参数
      fileOptions: [{ //附件类型树表
        id: 1,
        label: '1.专利资料',
        type: '专利资料'
      }, {
        id: 2,
        label: '2.授权文件',
        type: '授权文件'
      }],
      loadingFj: false,
      xg: false, //判断是新增还是修改 (false新增 true修改)
      allFilesUploaded: false, // 添加这个来追踪所有文件是否上传完成
      fjUpload: false, //附件上传弹窗
      //要修改的 专利申报id
      zlsbIdEdit: "",
      uploadFileUrl: process.env.VUE_APP_BASE_API + "/common/upload", // 上传文件服务器地址
      fileList: [],
      headers: {Authorization: "Bearer " + getToken()},
      number: 0,
      uploadList: [],
      fileType: ["doc", "xls", "ppt", "txt", "pdf", "docx", "zip"],
      getZlSbId: null, //从后端获取的专利申报主键ID (UUID)
      activeName: 'zlzcsqxx', //初始打开的标签页
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 子表选中数据
      checkedZlglZlsbFj: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 专利申报表格数据
      zlsbList: [],
      // 专利申报附件表格数据
      zlglZlsbFjList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        zlName: null,
        sqNd: null,
        zlLx: null,
        ssLy: null,
        ytGc: null,
        kyXm: null,
        xmsbId: null,
        userId: this.$store.state.user.id,
        deptId: null,
        processStatus: null,
        zlFmr: null,
        sbDw: null,
      },
      // 附件查询参数
      queryParamsFj: {
        pageNum: 1,
        pageSize: 100,
        zlsbId: null,
        fileType: null,
        fileName: null,
        fileSize: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        sqSqTime: [{required: true, message: "申请日期不能为空", trigger: "blur"}],
        sqDgName: [{required: true, message: "定稿名称不能为空", trigger: "blur"}],
        sqZlh: [{required: true, message: "专利号不能为空", trigger: "blur"}],
      },
      zlSqRules: {
        sqTime: [{required: true, message: "授权日期不能为空", trigger: "blur"}],
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    // 查询详情信息
    handleButtonClick(row) {
      this.$refs.zlSbXq.handleOpen(row);
    },
    //查询进度
    handleJinDu(row) {
      this.$refs.picture.handleOpen(row);
    },
    //点击行内任意地方选中行
    clickRow(row) {
      this.selectedRow = row; // 更新选中的行
      const table = this.$refs.table;
      const selectedRows = table.selection;

      // 否则取消之前选中的行，并选中当前点击的行
      selectedRows.forEach(selectedRow => {
        table.toggleRowSelection(selectedRow);
      });
      table.toggleRowSelection(row);
    },
    clickFirstNode() {
      this.$nextTick(() => {
        const firstNode = this.$refs.tree.store.nodesMap['1']; // 默认点击id为1的节点
        if (firstNode) {
          this.$refs.tree.setCurrentKey(firstNode.key);
          this.handleNodeClicks(firstNode.data);
        }
      });
    },
    handleNodeClicks(data) {
      this.loadingFj = true
      this.zlsbFileType = data.type
      this.queryParamsFj.fileType = this.zlsbFileType
      selectZlsbFjList(this.queryParamsFj).then(resFileList => {
        this.zlglZlsbFjList = resFileList.rows;
        this.loadingFj = false
      })
    },
    // 节点单击事件
    handleNodeClick(data, node) {
      this.loadingFj = true
      if (node.level > 0 && node.data.children && node.data.children.length > 0) { // 检查是否有子节点
        const firstChildNode = node.data.children[0]; // 获取第一个子节点
        this.$refs.tree.setCurrentKey(firstChildNode.id); // 设置当前选中的节点为第一个子节点
        data = firstChildNode; // 更新 data 为第一个子节点的数据
        this.zlsbFileType = data.type
        this.queryParamsFj.fileType = this.zlsbFileType
        selectZlsbFjList(this.queryParamsFj).then(resFileList => {
          this.zlglZlsbFjList = resFileList.rows;
          this.loadingFj = false
        })
      } else {
        //根据附件类型查询附件列表
        this.zlsbFileType = data.type
        this.queryParamsFj.fileType = this.zlsbFileType
        selectZlsbFjList(this.queryParamsFj).then(resFileList => {
          this.zlglZlsbFjList = resFileList.rows;
          this.loadingFj = false
        })
      }
    },
    // 筛选节点
    filterNode(value, data) {
      if (!value) return true;
      return data.label.indexOf(value) !== -1;
    },
    // 文件下载处理
    handleDownload(row) {
      const resource = row.fileName;
      // 默认方法
      this.$download.resource(resource);
    },
    // 获取文件名原名
    getFileNames(row) {
      // 从路径中提取文件名
      return row.fileName.split('/').pop(); // 返回文件名部分
    },
    //关闭上传附件弹窗后
    fjClose() {
      this.fileList = []
      this.allFilesUploaded = false
      this.fjUpload = false
    },
    //上传文件之前的钩子
    handleBeforeUpload(file) {
      let that = this;
      // 校检文件类型
      if (this.fileType) {
        const fileName = file.name.split('.');
        const fileExt = fileName[fileName.length - 1];
        const isTypeOk = this.fileType.indexOf(fileExt) >= 0;
        if (!isTypeOk) {
          this.$modal.msgError(`文件格式不正确, 请上传${this.fileType.join("/")}格式文件!`);
          return false;
        }
        // 校检文件大小
        if (this.fileSize) {
          const isLt = file.size / 1024 / 1024 < this.fileSize;
          if (!isLt) {
            this.$modal.msgError(`上传文件大小不能超过 ${this.fileSize} MB!`);
            return false;
          }
        }
        this.$modal.loading("正在上传文件，请稍候...");
        this.number++;
        return true;
      }
    },
    // 对象转成指定字符串分隔
    listToString(list, separator) {
      let strs = "";
      separator = separator || ",";
      for (let i in list) {
        strs += list[i].url + separator;
      }
      return strs !== '' ? strs.substr(0, strs.length - 1) : '';
    },
    // 上传失败
    handleUploadError() {
      this.$modal.msgError("上传文件失败，请重试");
      this.$modal.closeLoading();
    },
    // 文件个数超出
    handleExceed() {
      this.$modal.msgError(`上传文件数量不能超过 ${this.limit} 个!`);
    },
    // 上传成功
    handleUploadSuccess(res, file) {
      let that = this;
      if (res.code === 200) {
        this.uploadList.push({name: res.fileName, url: res.fileName, size: that.formatFileSize(file.size)});
        let xzItemFile = {
          "zlsbId": that.getZlSbId,
          "fileType": that.zlsbFileType,
          "fileName": res.fileName,
          "fileSize": that.formatFileSize(file.size)
        };
        let xgItemFile = {
          "zlsbId": that.zlsbIdEdit,
          "fileType": that.zlsbFileType,
          "fileName": res.fileName,
          "fileSize": that.formatFileSize(file.size)
        };
        if (this.xg === false) {
          // 点击新增按钮的上传
          insertZlsbFjByZlsbId(xzItemFile).then(resFil => {
            that.getZlsbFjList();
          })
        } else if (this.xg === true) {
          // 点击修改按钮的上传
          insertZlsbFjByZlsbId(xgItemFile).then(resFil => {
            that.getZlsbFjList();
          })
        }
        this.uploadedSuccessfully();
      } else {
        this.number--;
        this.$modal.closeLoading();
        this.$modal.msgError(res.msg);
        this.$refs.fileUpload.handleRemove(file);
        this.uploadedSuccessfully();
      }
      this.allFilesUploaded = true
      this.$modal.msgSuccess("上传成功")
      // this.fjShangChuan = false
    },
    getZlsbFjList() {
      let that = this;
      if (this.xg === false) {
        //点击新增 上传文件后的文件列表
        this.queryParamsFj.zlsbId = that.getZlSbId
        this.queryParamsFj.fileType = this.zlsbFileType
        selectZlsbFjList(this.queryParamsFj).then(resFileList => {
          this.zlglZlsbFjList = resFileList.rows;
        })
      } else {
        //点击修改 上传文件后的文件列表
        this.queryParamsFj.zlsbId = that.zlsbIdEdit
        this.queryParamsFj.fileType = this.zlsbFileType
        selectZlsbFjList(this.queryParamsFj).then(resFileList => {
          this.zlglZlsbFjList = resFileList.rows;
        })
      }
    },
    // 显示文件大小为KB, MB, GB, TB
    formatFileSize(size) {
      if (size === 0) return '0 Bytes';
      const k = 1024;
      const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
      const i = Math.floor(Math.log(size) / Math.log(k));
      return parseFloat((size / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];
    },
    // 上传结束处理
    uploadedSuccessfully() {
      if (this.number > 0 && this.uploadList.length === this.number) {
        this.fileList = this.fileList.concat(this.uploadList);
        this.fileList = this.fileList.map(item => {
          // 使用split方法去除name中的特定前缀
          item.name = item.name.split('/').pop();
          return item;
        });
        this.uploadList = [];
        this.number = 0;
        this.$emit("input", this.listToString(this.fileList));
        this.$modal.closeLoading();
      }
    },
    //专利申报附件上传按钮
    zlsbFileUpload() {
      this.fjUpload = true;
    },
    /** 查询专利申报列表 */
    getList() {
      this.loading = true;
      selectZlBySqDj(this.queryParams).then(response => {
        this.zlsbList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        zlsbId: this.getZlSbId,
        zlName: null,
        sqNd: new Date().getFullYear(),
        zlLx: null,
        sbTime: this.getCurrentDate(),
        ssLy: null,
        ytGc: null,
        ssRq: null,
        sfzHm: null,
        dyFmr: null,
        qtFmr: null,
        kjryId: null,
        sbDw: null,
        zlqR: null,
        lxPhone: null,
        lxr: null,
        qqFwJg: null,
        bz: null,
        kyXm: null,
        xmsbId: null,
        sqSqTime: null,
        sqDgName: null,
        sqTime: null,
        sqZlh: null,
        idWhere: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        userId: null,
        deptId: null
      };
      this.zlglZlsbFjList = [];
      this.resetForm("formDialog");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      let ids = selection.map(item => item.zlsbId)
      if (ids.length === 1) {
        this.ids = ids[0]
      } else {
        this.ids = ids
      }
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 专利申请信息填写 */
    zlSqUpdate(row) {
      // this.reset();
      this.xg = true
      const zlsbId = row.zlsbId || this.ids
      this.zlsbIdEdit = row.zlsbId || this.ids
      getZlsb(zlsbId).then(response => {
        this.form = response.data;

        this.queryParamsFj.zlsbId = zlsbId
        this.queryParamsFj.fileType = this.zlsbFileType
        selectZlsbFjList(this.queryParamsFj).then(resFileList => {
          this.zlglZlsbFjList = resFileList.rows;
        })
        // this.zlglZlsbFjList = response.data.zlglZlsbFjList;
        this.activeName = 'zlzcsqxx'
        this.open = true;
        this.title = "专利申请信息填写";
      });
    },
    /** 专利授权信息填写 */
    zlSqcgUpdate(row) {
      this.xg = true
      const zlsbId = row.zlsbId || this.ids
      this.zlsbIdEdit = row.zlsbId || this.ids
      getZlsb(zlsbId).then(response => {
        this.form = response.data;

        this.queryParamsFj.zlsbId = zlsbId
        this.queryParamsFj.fileType = this.zlsbFileType
        selectZlsbFjList(this.queryParamsFj).then(resFileList => {
          this.zlglZlsbFjList = resFileList.rows;
        })
        // this.zlglZlsbFjList = response.data.zlglZlsbFjList;
        this.activeName = 'zlzcsqxx'
        this.zlSq = true;
        this.title = "专利授权信息填写";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["formDialog"].validate(valid => {
        if (valid) {
          let processInstanceId = this.selectedRow.processInstanceId
          this.form.zlglZlsbFjList = this.zlglZlsbFjList;
          if (this.form.sqTime == null) { //专利申请信息填写
            zlSqUpdate(this.form, processInstanceId).then(response => {
              this.$modal.msgSuccess("填写成功");
              this.open = false;
              this.getList();
              this.xg = false
            });
          } else if (this.form.sqTime != null) { //专利授权信息填写
            zlSqcgUpdate(this.form, processInstanceId).then(response => {
              this.$modal.msgSuccess("授权信息填写成功");
              this.zlSq = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 专利申报附件删除按钮操作 */
    handleDeleteZlglZlsbFj() {
      if (this.checkedZlglZlsbFj.length == 0) {
        this.$modal.msgError("请先选择要删除的专利申报附件数据");
      } else {
        const fjIds = this.checkedZlglZlsbFj;
        this.$modal.confirm('确定删除选中记录？').then(function () {
          return delZlFj(fjIds);
        }).then(() => {
          this.queryParamsFj.zlsbId = this.zlsbIdEdit
          this.queryParamsFj.fileType = this.zlsbFileType
          selectZlsbFjList(this.queryParamsFj).then(resFileList => {
            this.zlglZlsbFjList = resFileList.rows;
          })
          this.$modal.msgSuccess("删除成功");
        }).catch(() => {
        });
      }
    },
    /** 复选框选中数据 */
    handleZlglZlsbFjSelectionChange(selection) {
      this.checkedZlglZlsbFj = selection.map(item => item.fjId)
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('zlsb/zlsb/export', {
        ...this.queryParams
      }, `zlsb_${new Date().getTime()}.xlsx`)
    },
  }
};
</script>

<style scoped>
.image-preview-wrapper {
  display: flex;
  justify-content: center; /* 水平居中 */
  align-items: center; /* 垂直居中，如果需要的话 */
}
</style>
